﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace WeiXinSDK.MP.Model
{
	public abstract class CustomMessageBaseModel
	{
		protected CustomMessageBaseModel(string toUser)
		{
			ToUser = toUser;
		}

		[JsonProperty("touser")]
		public string ToUser { get; set; }

		[JsonProperty("msgtype")]
		public abstract string MsgType { get; }

		[JsonProperty("customservice")]
		public KFAccount CustomService { get; set; }

		public class KFAccount
		{
			[JsonProperty("kf_account")]
			public string Account { get; set; }
		}
	}

	/// <summary> 文本消息 </summary>
	public class TestCustomMessageModel : CustomMessageBaseModel
	{
		public TestCustomMessageModel(string text, string toUser)
			: base(toUser)
		{
			Text = new TextContent { Content = text };
		}

		public override string MsgType
		{
			get { return "text"; }
		}

		[JsonProperty("text", Order = 2)]
		public TextContent Text { get; set; }

		public class TextContent
		{
			[JsonProperty("content")]
			public string Content { get; set; }
		}
	}


	/// <summary> 图片消息 </summary>
	public class ImageCustomMessageModel : CustomMessageBaseModel
	{
		public ImageCustomMessageModel(string mediaId, string toUser)
			: base(toUser)
		{
			Image = new ImageContent { MediaId = mediaId };
		}

		public override string MsgType
		{
			get { return "image"; }
		}

		[JsonProperty("image")]
		public ImageContent Image { get; set; }
		public class ImageContent
		{
			[JsonProperty("media_id")]
			public string MediaId { get; set; }
		}
	}
	
	/// <summary> 语音消息 </summary>
	public class VoiceCustomMessageModel : CustomMessageBaseModel
	{
		public VoiceCustomMessageModel(string mediaId, string toUser)
			: base(toUser)
		{
			Voice = new VoiceContent { MediaId = mediaId };
		}
		public override string MsgType
		{
			get { return "voice"; }
		}

		[JsonProperty("voice")]
		public VoiceContent Voice { get; set; }

		public class VoiceContent
		{
			[JsonProperty("media_id")]
			public string MediaId { get; set; }
		}
	}

	/// <summary> 视频消息 </summary>
	public class VideoCustomMessageModel : CustomMessageBaseModel
	{
		public VideoCustomMessageModel(string toUser, string mediaId, string thumbMediaId, string title, string desc)
			: base(toUser)
		{
			Video = new VideoContent { Description = desc, MediaId = mediaId, ThumbMediaID = thumbMediaId, Title = title };
		}

		public override string MsgType
		{
			get { return "video"; }
		}

		[JsonProperty("video")]
		public VideoContent Video { get; set; }

		public class VideoContent
		{
			[JsonProperty("media_id")]
			public string MediaId { get; set; }

			/// <summary> 缩略图的媒体ID </summary>
			[JsonProperty("thumb_media_id")]
			public string ThumbMediaID { get; set; }

			/// <summary> 视频消息的标题 </summary>
			[JsonProperty("title")]
			public string Title { get; set; }

			/// <summary> 视频消息的描述 </summary>
			[JsonProperty("description")]
			public string Description { get; set; }
		}
	}

	/// <summary> 音乐消息 </summary>
	public class MusicCustomMessageModel : CustomMessageBaseModel
	{
		public MusicCustomMessageModel(string toUser, string title, string desc, string musicUrl, string hqMusicUrl, string thumbMediadId)
			: base(toUser)
		{
			Music = new MusicContent
			{
				Description = desc,
				ThumbMediaID = thumbMediadId,
				Title = title,
				HqMusicUrl = hqMusicUrl,
				MusicUrl = musicUrl
			};
		}
		public override string MsgType
		{
			get { return "music"; }
		}

		[JsonProperty("music")]
		public MusicContent Music { get; set; }

		public class MusicContent
		{
			[JsonProperty("title")]
			public string Title { get; set; }

			/// <summary> 视频消息的描述 </summary>
			[JsonProperty("description")]
			public string Description { get; set; }

			/// <summary> 音乐链接 </summary>
			[JsonProperty("musicurl")]
			public string MusicUrl { get; set; }

			/// <summary> 高品质音乐链接，wifi环境优先使用该链接播放音乐 </summary>
			[JsonProperty("hqmusicurl")]
			public string HqMusicUrl { get; set; }

			/// <summary> 缩略图的媒体ID </summary>
			[JsonProperty("thumb_media_id")]
			public string ThumbMediaID { get; set; }
		}
	}

	/// <summary> 图文消息 </summary>
	public class NewsCustomMessageModel : CustomMessageBaseModel
	{
		public NewsCustomMessageModel(string toUser, IEnumerable<NewsItem> news)
			: base(toUser)
		{
			News = new NewsContent { Articles = news };
		}

		public override string MsgType
		{
			get { return "news"; }
		}

		[JsonProperty("news")]
		public NewsContent News { get; set; }

		public class NewsContent
		{
			[JsonProperty("articles")]
			public IEnumerable<NewsItem> Articles { get; set; }
		}

		public class NewsItem
		{
			/// <summary> 标题 </summary>
			[JsonProperty("title")]
			public string Title { get; set; }

			/// <summary> 描述 </summary>
			[JsonProperty("description")]
			public string Description { get; set; }

			/// <summary> 点击后跳转的链接 </summary>
			[JsonProperty("url")]
			public string Url { get; set; }

			/// <summary> 图文消息的图片链接，支持JPG、PNG格式，较好的效果为大图640*320，小图80*80 </summary>
			[JsonProperty("picurl")]
			public string PicUrl { get; set; }

		}
	}


}
